package com.ciquan.server.bean;

import com.ciquan.server.util.json.DateJsonSerializer;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.Date;

/**
 * Created by bjliwei2014 on 2015/2/27.
 */
public class Message implements Comparable<Message>{

    private Integer id;

    private Integer worksId;

    private Integer sendUserId;

    private Integer receiveUserId;

    private String content;

    private String imagePath;

    private Integer isRead;

    @JsonSerialize(using = DateJsonSerializer.class)
    private Date cTime;

    private String name;

    private String thumbPicUrl;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getWorksId() {
        return worksId;
    }

    public void setWorksId(Integer worksId) {
        this.worksId = worksId;
    }

    public Integer getSendUserId() {
        return sendUserId;
    }

    public void setSendUserId(Integer sendUserId) {
        this.sendUserId = sendUserId;
    }

    public Integer getReceiveUserId() {
        return receiveUserId;
    }

    public void setReceiveUserId(Integer receiveUserId) {
        this.receiveUserId = receiveUserId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        if(!StringUtils.isBlank(imagePath)) {
            this.imagePath = "http://182.92.107.35/uploads/pictures/" + imagePath;
        }

        else {
            this.imagePath = imagePath;
        }
    }

    public Integer getIsRead() {
        return isRead;
    }

    public void setIsRead(Integer isRead) {
        this.isRead = isRead;
    }

    public Date getcTime() {
        return cTime;
    }

    public void setcTime(Date cTime) {
        this.cTime = cTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getThumbPicUrl() {
        return thumbPicUrl;
    }

    public void setThumbPicUrl(String thumbPicUrl) {
        this.thumbPicUrl = thumbPicUrl;
    }

    @Override
    public int compareTo(Message o) {
        if(this.cTime.getTime() > o.cTime.getTime()) {
            return -1;
        }

        else if(this.cTime.getTime() < o.cTime.getTime()) {
            return 1;
        }
        return 0;
    }
}
